import { FormProps, FormSchema } from '@/components/Table'
import { BasicColumn } from '@/components/Table/src/types/table'
import { getBeforeTime } from '@/utils/dateUtil'
import dayjs, { Dayjs } from 'dayjs'

// 订单列表
export function getOrderBasicColumns(): BasicColumn[] {
  return [
    {
      title: '企业名称',
      fixed: 'left',
      dataIndex: 'orgName'
    },
    {
      title: '企业税号',
      dataIndex: 'taxesNumber'
    },
    {
      title: '所属租户',
      dataIndex: 'topOrgName'
    },
    {
      title: '渠道名称',
      dataIndex: 'channelName'
    },
    {
      title: '订单总数',
      align: 'right',
      width: 100,
      sorter: true,
      dataIndex: 'sumCount'
    },
    {
      title: '开票成功',
      align: 'right',
      width: 100,
      sorter: true,
      dataIndex: 'sucCount'
    },
    {
      title: '开票中',
      align: 'right',
      width: 100,
      sorter: true,
      dataIndex: 'ingCount'
    },
    {
      title: '开票失败',
      align: 'right',
      width: 100,
      sorter: true,
      dataIndex: 'failCount'
    },
    {
      title: '开票成功率',
      align: 'right',
      width: 100,
      dataIndex: 'sucRate'
    },
    {
      title: '开票金额',
      align: 'right',
      width: 100,
      sorter: true,
      dataIndex: 'sumAmt'
    }
  ]
}

export function getSearchFormConfig(): Partial<FormProps> {
  return {
    labelWidth: 80,
    baseColProps: {
      lg: 10,
      xl: 8,
      xxl: 6
    },
    schemas: [
      {
        field: '[beginDate, endDate]',
        component: 'RangePicker',
        label: '统计时间',
        defaultValue: [getBeforeTime(31, 'day'), getBeforeTime(0, 'day')],
        componentProps: {
          valueFormat: 'YYYY-MM-DD',
          format: 'YYYY-MM-DD',
          allowClear: false,
          disabledDate: (current: Dayjs) => {
            const today = dayjs().startOf('day') // 获取今天的开始时间
            const selectedDate = dayjs(current).startOf('day') // 获取选中日期的开始时间
            return selectedDate.isAfter(today)
          }
        }
      },
      {
        field: 'orgName',
        label: '企业名称',
        component: 'Input'
      },
      {
        field: 'taxesNumber',
        label: '企业税号',
        component: 'Input'
      }
    ]
  }
}
